package com.bicon.botu.file.upload.rpc;

import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.core.base.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bicon.botu.file.upload.service.FileUploadService;

/**
 * 删除文件rpc
 *
 * @author 裴志鹏
 * @date 2018/2/2 11:26
 */
@RequestMapping(value = "/V2.0.0/rpc/file")
@RestController
public class DeleteFileRpc extends BaseController {

    @Autowired
    FileUploadService fileUploadService;

    /**
     * 删除文件
     *
     * @param type     文件类型：0：图片，1：视频，2：语音
     * @param filePath 文件路径
     * @return
     */
    @RequestMapping(value = "/deleteFile", method = RequestMethod.POST)
    public BaseResult deleteFileOperation(@RequestParam String type, @RequestParam String filePath) {
        if (StringUtils.isAnyBlank(type,filePath)){
            return sendResult400();
        }
        boolean result=fileUploadService.deleteFileOperation(type,filePath);
        if (result) {
            return sendResult200();
        } else {
            return sendResult500("文件不存在");
        }
    }
}
